<template>
	<view class="userInfo-box">
		<view class="userInfo">
			<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				<image :src="userInfo.avatarUrl"></image>
			</button> 
			<text>{{userInfo.nickName}}</text>
		</view>
		<view class="box">
			<view class="menu-list default">
				<view class="menu-item">
					<text>8</text>
					<text>收藏的店铺</text>
				</view>
				<view class="menu-item">
					<text>14</text>
					<text>收藏的物品</text>
				</view>
				<view class="menu-item">
					<text>8</text>
					<text>关注的商品</text>
				</view>
				<view class="menu-item">
					<text>8</text>
					<text>足迹</text>
				</view>
			</view>
			<view class="ShopRecord default">
				<text>我的订单</text>
				<view class="ShopRecord-list">
					<view class="ShopRecord-item">
						<image src="/static/user/待付款.png"></image>
						<text>待付款</text>
					</view>
					<view class="ShopRecord-item">
						<image src="/static/user/待收货.png"></image>
						<text>待收货</text>
					</view>
					<view class="ShopRecord-item">
						<image src="/static/user/退款.png"></image>
						<text>退款/退货</text>
					</view>
					<view class="ShopRecord-item">
						<image src="/static/user/全部订单.png"></image>
						<text>全部订单</text>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="item">
					<text>收货地址</text>
					<uni-icons type="forward"></uni-icons>
				</view>
				<view class="item">
					<text>联系客服</text>
					<uni-icons type="forward"></uni-icons>
				</view>
				<view class="item" @click="exit">
					<text>退出登录</text>
					<uni-icons type="forward"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	export default {
		name:"my-userInfo",
		data() {
			return {
				
			};
		},
		computed: {
			...mapState('m_user', ['userInfo']),
		},
		methods: {
			...mapMutations('m_user', ['deleteUserInfo','updateUserInfo']),
			async exit(){
				const result = await uni.showModal({
					title: '黑马优购',
					content: '你怎么忍心离开本宝宝的',
					cancelText: '不走了',
					confirmText: '不爱了'
				})
				if(result.confirm){
					this.deleteUserInfo()
					return uni.$showMsg('退出成功')
				}
			},
			onChooseAvatar(e){
				const newUserInfo = {
					...this.userInfo,
					avatarUrl: e.detail.avatarUrl
				}
				this.updateUserInfo(newUserInfo)
			}
		}
	}
</script>

<style lang="scss">
.userInfo-box{
	background-color: #f4f4f4;
	height: 100vh;
	.userInfo{
		height: 200px;
		background-color: #C00000;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		color: white;
		button{
			background-color: transparent;
			&::after{
				border: none;
			}
		}
		image{
			width: 85px;
			height: 85px;
			display: block;
			border-radius: 50px;
			border: 2px solid white;
			box-shadow: 0px 1px 5px black;
			margin-bottom: 10px;
		}
	}
	.box{
		width: 90%;
		margin: 0 auto;
		position: relative;
		top: -15px;
		.default{
			background-color: white;
			border-radius: 5px;
			padding: 10px;
			margin-bottom: 10px;
		}
		.menu-list{
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 14px;
			.menu-item{
				display: flex;
				flex-direction: column;
				align-items:center
			}
		}
		.ShopRecord{
			.ShopRecord-list{
				font-size: 14px;
				display: flex;
				justify-content: space-between;
				margin-top: 15px;
				.ShopRecord-item{
					display: flex;
					flex-direction: column;
					align-items: center;
					image{
						width: 30px;
						height: 30px;
					}
				}
			}
		}
	}
	.list{
		background-color: white;
		border-radius: 5px;
		.item{
			display: flex;
			padding: 10px;
			justify-content: space-between;
			align-items: center;
		}
	}
}
</style>